package com.mohan.dlxj.controller;

import com.mohan.dlxj.common.JsonResult;
import com.mohan.dlxj.common.R;
import com.mohan.dlxj.pojo.Flaw;
import com.mohan.dlxj.pojo.FlawType;
import com.mohan.dlxj.service.FlawService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("flaw")
public class FlawController {
  @Autowired
  private FlawService flawService;

  @GetMapping("getType")
  public JsonResult getType(Integer page,Integer limit) {
    JsonResult jsonResult= flawService.getCircuitList(page,limit);
    return jsonResult;
  }

  @PostMapping("savaType")
  public R saveType(FlawType flawType) {
    R r = new R();
    flawService.saveType(flawType);
    r.setCode(200);
    r.setMsg("插入类型成功");
    return r;
  }

  @PostMapping("updateTypeById")
  public R updateTypeById(FlawType flawType) {
    R r = new R();
    flawService.updateType(flawType);
    r.setCode(200);
    r.setMsg("更新类型成功");
    return r;
  }


  @GetMapping("getFlaw")
  public JsonResult getFlaw(Integer page,Integer limit) {
    JsonResult jsonResult= flawService.getFlawList(page,limit);
    return jsonResult;
  }

  @PostMapping("updateFlaw/{id}")
  public R updateFlaw(@PathVariable long id) {
    R r = new R();
    flawService.updateFlaw(id);
    r.setCode(200);
    r.setMsg("更新缺陷成功");
    return r;
  }

  @GetMapping("getSomeFlaw")
  public JsonResult selectSomeFlaw(long page, long limit,Flaw flaw){
    JsonResult jsonResult= flawService.getSomeFlawList(page,limit,flaw);
    return jsonResult;
  }

  @PostMapping("ensureLevel")
  public R ensureLevel(long id,long level) {
    R r = new R();
    flawService.ensureLevel(id,level);
    r.setCode(200);
    r.setMsg("确认缺陷成功");
    return r;
  }
}
